<?php
namespace app\site\model;

use app\common\library\Model;
use think\model\concern\SoftDelete;
class Site extends Model
{
    protected $dateFormat = 'Y-m-d';
    protected $append = [
        'deadline_text',
        'time_text',
        'type_text'
    ];

    /**
	 * [CustomInfo 客户信息]
	 */
    protected function customInfo(){
		return $this->hasOne("app\\custom\\model\\Custom",'current_id', 'custom_id');
	}
    /**
     * [setNameAttr description]
     * @param [type] $value [description]
     */
    public function setTypeAttr($value)
    {
        return implode(',', $value);
    }
    /**
     * [settingInfo 设置信息]
     * @return [type] [description]
     */
    protected function settingInfo(){
        return $this->hasMany("app\\site\\SiteSetting",'site_id','id');
    }
    /**
     * [getDeadLineTextAttr description]
     * @return [type] [description]
     */
    protected function getDeadlineTextAttr($value,$data){
        if(empty($data['deadline'])){
            return '永久';
        }else{
            return date('Y-m-d',$data['deadline']);
        }
    }

    //转换编辑器内容
    public function getDescAttr($value,$data){
        return htmlspecialchars_decode(htmlspecialchars_decode($data['desc']));
    }

    /**
     * [getTimeTextAttr description]
     * @param  [type] $value [description]
     * @param  [type] $data  [description]
     * @return [type]        [description]
     */
    protected function getTimeTextAttr($value,$data){
        if(empty($data['time'])){
            return '永久';
        }else{
            return $data['time'].'个月';
        }
    }
    /**
     * [getTypeTextAttr description]
     * @param  [type] $value [description]
     * @param  [type] $data  [description]
     * @return [type]        [description]
     */
    protected function getTypeTextAttr($value,$data){
        if(!empty($data['type'])){
            $result = '';
            foreach (explode(',', $data['type']) as $key => $type) {
                switch ($type) {
                    case 'baidu':
                        $result .= '百度小程序 ';
                        break;
                    case 'wechat':
                        $result .= '微信小程序 ';
                        break;
                    default:
                        break;
                }
            }
            return $result;
        }
    }
}